import time

from src3.Base.Base import Base
from selenium.webdriver.common.by import By


class Page(Base):
    # 用第一种方法找到搜素框
    input_01_loc = (By.ID,'input')
    def input_01(self):
        self.send_keys(self.input_01_loc,'我在做软件测试')
    # 清空第一次的内容
    input_clear_loc = (By.ID, 'input')
    def input_clear(self):
        self.clear(self.input_clear_loc)

    # 用第二种方法找到搜素框
    # 输入“我在做软件测试”
    input_02_loc = (By.XPATH, '//*[@id="input"]')
    def input_02(self):
        self.send_keys(self.input_02_loc, '我在做软件测试')
    # 点击搜索
    #search-button
    click_button_loc = (By.ID, 'search-button')
    def click_button(self):
        self.click(self.click_button_loc)
    # 验证搜索结果是否包含你搜的关键字
    # //*[@id="e_idea_pp"]/li[1]/div[1]/span[2]/a
    dy1_text_loc = (By.XPATH, '//*[@id="e_idea_pp"]/li[1]/div[1]/span[2]/a')
    def dy1_text(self):
        self.text(self.dy1_text_loc)
    # 截图
    jietu_loc = (By.XPATH,'/html/body')
    def jietus(self):
        self.jietu(self.jietu_loc)
    # 输出所有搜索到的网站名称
    name1_loc = (By.ID,'main')
    def name1(self):
        return self.text(self.name1_loc)
    # 翻到下一页 //*[@id="page"]/a[1]
    click_02_loc = (By.XPATH, '//*[@id="page"]/a[1]')
    def click_02(self):
        self.click(self.click_02_loc)
    # 输出所有搜索到的网站名称
    name2_loc = (By.ID, 'main')
    def name2(self):
        return self.text(self.name2_loc)



    def test_360_01(self):
        # 打开https: // www.so.com /
        self.open_url('https://www.so.com/')
        self.input_01()
        time.sleep(2)
        self.input_clear()
        time.sleep(2)
        self.input_02()
        time.sleep(2)
        self.click_button()
        time.sleep(5)
        print(self.dy1_text())
        assert '我在做软件测试',str(self.dy1_text())
        self.jietus()
        print(self.name1())
        time.sleep(5)
        self.click_02()
        print(self.name2())

